package com.asion.qkan.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.asion.qkan.R;
import com.asion.qkan.entry.RecommendEntry;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by asion on 16-10-15.
 */

public class TuijianItemAdapter extends RecyclerView.Adapter<TuijianItemAdapter.MyHolder> {

    private List<RecommendEntry.DataBean.TopicsBean> list;
    private Context context;

    private OnItemClickListener onItemClickListener;

    public TuijianItemAdapter(List<RecommendEntry.DataBean.TopicsBean> list, Context context,OnItemClickListener onItemClickListener) {
        this.list = list;
        this.context = context;
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.tuijian_item_item, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        RecommendEntry.DataBean.TopicsBean topicsBean = list.get(position);
        holder.itemImage.setImageURI(topicsBean.getVertical_image_url());
        holder.itemTitle.setText(topicsBean.getTitle());
        holder.itemName.setText(topicsBean.getUser().getNickname());
        holder.itemView.setOnClickListener(v->onItemClickListener.onItemClick(topicsBean));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class MyHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.item_image)
        SimpleDraweeView itemImage;
        @BindView(R.id.item_title)
        TextView itemTitle;
        @BindView(R.id.item_name)
        TextView itemName;

        public MyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(RecommendEntry.DataBean.TopicsBean bean);
    }
}
